home *** CD-ROM | disk | FTP | other *** search
/ PC World 2007 January / PCWorld_2007-01_cd.bin / v cisle / autoit / autoit-v3.2.0.1-setup.exe / Examples / Helpfile / StringRegExp.au3 < prev    next >
Text File  |  2006-06-17  |  1KB  |  33 lines

  1. Local $sPattern, $sTest, $vResult, $nFlag
  2.  
  3. $sPattern = InputBox("StringRegExp Sample", "What is the pattern to test?")
  4. $sTest = InputBox("StringRegExp Sample", "What is the line to test?")
  5. $vResult = StringRegExp($sTest, $sPattern)
  6. Select
  7. Case @Error = 2 
  8.     ; Error.  The pattern was invalid.  $vResult = position in $sPattern where error occurred.
  9. Case @Error = 0
  10.    if @Extended  Then
  11.       ; Success.  Pattern matched.  $vResult matches @Extended
  12.    Else
  13.       ; Failure.  Pattern not matched.  $vResult = ""
  14.    EndIf
  15. EndSelect
  16.  
  17. $sPattern = InputBox("StringRegExp Sample", "What is the pattern to test?")
  18. $sTest = InputBox("StringRegExp Sample", "What is the line to test?")
  19. $nFlag = InputBox("StringRegExp Sample", "What flag to use?  0 - true/false, 1 - single pattern array return, 3 - global pattern array return")
  20. $vResult = StringRegExp($sTest, $sPattern, $nFlag)
  21. Select
  22. Case @Error = 1 
  23.    ; Error.  Flag is bad.  $vResult = ""
  24. Case @Error = 2 
  25.     ; Error.  The pattern was invalid.  $vResult = position in $sPattern where error occurred.
  26. Case @Error = 0
  27.    if @Extended  Then
  28.       ; Success.  Pattern matched.  $vResult has the text from the groups or true (1), depending on flag. 
  29.    Else
  30.       ; Failure.  Pattern not matched.  $vResult = "" or false (0), depending on flag.
  31.    EndIf
  32. EndSelect
  33.